<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>元素的获取</title>
</head>
<body>
    <div id="div1">div1</div>
    <div id="div2">div2</div>
    <div class="cls">div3</div>
    <div class="cls">div4</div>
    <input type="text" name="username"/>
</body>
<script>
    <!--getElmentById-->
    let div1=document.getElementById("div");
//    alert(div1)
    console.log(div1);

    //2.getElementsByTagName() 根据元素名称获取元素对象们，返回数组
    let divs=document.getElementsByTagName("div");
//    遍历数组，获取每一个元素
    for (let d of divs){
        console.log(d);
    }

//    3.getElementsByName("username")根据class属性获取元素对象们，返回数组
    let cls=document.getElementsByName("username");
</script>